<?php /*a:2:{s:73:"D:\leruge_program\local\admin\application\admin\view\admin\edit_role.html";i:1592209365;s:71:"D:\leruge_program\local\admin\application\admin\view\common\__base.html";i:1592181449;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style id="layuimini-bg-color">
    </style>
    
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        
<form class="layui-form layui-form-pane">
    <input type="hidden" name="id" id="id" value="<?php echo htmlentities($roleInfo['id']); ?>">
    <div class="layui-form-item">
        <label class="layui-form-label">角色名</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="title" value="<?php echo htmlentities($roleInfo['title']); ?>" id="title" lay-verify="required" placeholder="角色名">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限选择</label>
        <div class="layui-input-block">
            <div id="tree"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="submit">设置</button>
        </div>
    </div>
</form>

    </div>
</div>

<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/static/admin/js/lay-config.js?v=2.0.0" charset="utf-8"></script>

<script>
    layui.use(['tree', 'jquery', 'form'], function () {
        let isClick = true,
            form = layui.form,
            tree = layui.tree,
            $ = layui.jquery,
            treeData = <?php echo $oneMenuList; ?>,
            selectedTreeData = ("<?php echo htmlentities($roleInfo['rules']); ?>").split(",");
        console.log(selectedTreeData)

        // 树状结构
        tree.render({
            elem: "#tree",
            data: treeData,
            showCheckbox: true,
            id: "tree"
        });
        tree.setChecked('tree', selectedTreeData);

        // 提交
        form.on("submit(submit)", function () {
            if (isClick) {
                isClick = false;
                let checkData = tree.getChecked("tree");
                let newData = [];
                for (let i = 0;i < checkData.length; i++) {
                    newData.push(checkData[i].id);
                    let children = checkData[i].children;
                    for (let j = 0;j < children.length;j++) {
                        newData.push(children[j].id);
                    }
                }
                if (newData.length == 0) {
                    isClick = true;
                    layer.msg("至少选择一个权限");
                } else {
                    $.post("<?php echo url('admin/admin/editRole'); ?>", {title: $("#title").val(), rules: newData.join(","), id: $("#id").val()}, function (res) {
                        if (res.code == 1) {
                            layer.msg(res.msg, function () {
                                location.reload();
                            });
                        } else {
                            isClick = true;
                            layer.msg(res.msg);
                        }
                    }, "json");
                }
            } else {
                layer.msg("不允许重复提交");
            }
            return false;
        });
    });
</script>

</body>
</html>
